package com.suma.platform.core;

import javax.servlet.Filter;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.suma.boot.mybatis.EnableDruid;
import com.suma.boot.mybatis.page.EnableMybatisPageHelper;
import com.suma.boot.redis.EnableRedis;
import com.suma.boot.swagger.EnableSwagger2Doc;
import com.suma.platform.core.filter.ApiAuthFilter;

/**
 * @author suma
 * @date 2018/1/10 上午10:27
 */
@SpringCloudApplication
@EnableFeignClients
@EnableHystrix
@MapperScan(basePackages = "com.suma.platform.core.mapper")
@EnableScheduling
@EnableSwagger2Doc
@EnableRedis
@EnableMybatisPageHelper
@EnableDruid
public class SumaPlatformCoreApplication {

    public static void main(String[] args) {
        SpringApplication.run(SumaPlatformCoreApplication.class, args);
    }

    /**
     * 配置过滤器
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean someFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(apiAuthFilter());
        registration.addUrlPatterns("/api/*");
        registration.addInitParameter("paramName", "paramValue");
        registration.setName("apiAuthFilter");
        return registration;
    }

    /**
     * 创建一个bean
     *
     * @return
     */
    @Bean(name = "apiAuthFilter")
    public Filter apiAuthFilter() {
        return new ApiAuthFilter();
    }
}
